import { downloadThirdpartApi } from "@/utils/apibase";

export async function toDataUrlByDownloadAsync(url) {
  const blob = await downloadThirdpartApi({
    url: url,
    method: "get",
    timeout: 60 * 1000
  });
  return await blobToDataURL(blob);
}

export function blobToDataURL(blob) {
  return new Promise((rs, rj) => {
    var a = new FileReader();
    a.onload = function (e) {
      rs(e.target.result);
    };
    a.onerror = function (e) {
      rj(e);
    };
    console.log("blob", blob);
    a.readAsDataURL(blob);
  });
}
